<script type="text/javascript">
$(function(){
	var pg = App.message.brokerIndex.ui, pp = pg.params,
		brokerGd = pg.seek('brokerGd'),
		main = pg.children('.main'),
		title = pg.children('.navi').seek('title');

	function callback() {
		App.show({
			ctx : 'message',
			action : 'brokerIndex'
		}, $.noop, App.main);
	}
	
	brokerGd.mac('grid', {
		key: 'addr',
		cols : [{
			field: 'addr', title : '中间件IP地址', width: 140
		}, {
			field: 'opt', title : '明细 ', width: 100,
			render: function(r, tr, me){
				var p=$('<div></div>');
				$('<span class="a"></span>').click(function(){
					var a = r.addr.split(":");
					$.post('/soagov/app/inst/find.do', { 
						ip: a[0],
						port: a[1]
					}, function(rs) {
						var ro = mac.eval(rs);
						if (ro.data == null ){
							mac.alert('未查询打任何应用信息');
						} else {
							showView(ro);
						}
					});
				}).append('查看').appendTo(p);
				p.append('&nbsp;');
				$('<span class="a"></span>').click(function(){
					var ip = r.addr.split(':')[0];
					App.show({
						title: 'JVM监控',
						ctx: 'base',
						action: 'appInstMonitor',
						params: {
							addr: r.addr,
							key: 'message-server'
						}
					}, callback, pg.parent());
				}).append('监控').appendTo(p);
				return p;
			}
		}],
		onRowClick: function(r){
			brokerGd.find('.tr').removeClass('selected');
			var a = brokerGd.selected = $(this).addClass('selected');
			a = a.attr('name');
			title.text(a);
			App.show({
				ctx: 'message',
				action: 'brokerQueue',
				params: a
			}, $.noop, main);
			return false;
		}
	});
	
	function showView(r){
		App.open({
			title: '应用查询',
			ctx: 'base',
			action: 'appInstView',
			model: true,
			params: r
		}, main); 
	}
	
	function init(o) {
		var nl = [];
		for (var k in o) {
			nl.push(o[k]);
		}
		if (nl.length) {
			brokerGd.loadData(nl);
		}
	}
	
	function adjust(){
		var h = pg.parent().height();
		pg.height(h);
		brokerGd.parent().height(h);
		brokerGd.adjust();
		main.height(h);
		main.width(pg.width() - brokerGd.width() - 1); 
	}
	
	$(window).resize(adjust);
	adjust();

	$.get(App.ctx + '/broker/list.do', function(rs) {
		var ro = mac.eval(rs);
		if (ro.success) {
			init(ro.data);
		} else {
			mac.alert(ro.data, ro.params);
		}
	});
	
});
</script>
<div class="navi">
	<span class="a" name="back">消息中间件</span>&gt;&gt;
	<span name="title">所有中间件</span>
</div>
<div class="fl">
	<div class="grid" name="brokerGd"></div>
</div>
<div class="main"></div>